package com.xiaoke.java;

import org.junit.Test;

/**
 * 测试String的不可变性
 *
 * @author yd
 * @version 1.0
 * @date 2022/2/28 19:19
 */
public class StringTest1 {

    @Test
    public void test1() {
        String s1 = "xiaoke"; //字面量定义的方式, "abc"存储在字符串常量池中
        String s2 = "xiaoke";

        System.out.println(s1 == s2);

        s2 = "xiaozhi";
        System.out.println(s1 == s2);

    }

    @Test
    public void test2(){
        String s1 = "xiaoke";
        String s2 = "xiaoke";
        s2 +="handsome";
        System.out.println(s2);
        System.out.println(s1);
        System.out.println(s1 == s2);
    }

    @Test
    public void test3(){
        String s1 = "xiaoke";
        String s2 = s1.replace('a', 'b');
        System.out.println(s2);
        System.out.println(s1 == s2);
    }
}
